package com.example.myapplication.Button;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_test;
    private TextView tv_result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enable);

        // 找到按钮和文本框
        Button btn_enable = findViewById(R.id.btn_enable);
        Button btn_disable = findViewById(R.id.btn_disable);
        btn_test = findViewById(R.id.btn_test);
        tv_result = findViewById(R.id.tv_result);

        // 为按钮添加点击事件监听器
        btn_enable.setOnClickListener(this);
        btn_disable.setOnClickListener(this);
        btn_test.setOnClickListener(this);
    }

    // 处理按钮点击事件
    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.btn_enable){
            btn_test.setEnabled(true);
            btn_test.setTextColor(Color.BLACK);
        } else if (v.getId() == R.id.btn_disable) {
            btn_test.setEnabled(false);
            btn_test.setTextColor(Color.GRAY);
        } if (v.getId() == R.id.btn_test) {
            tv_result.setText("按钮被点击了");
        }
    }
}